/**
 * 
 */
package org.metaverse.warehouse.test;

import java.io.IOException;
import java.util.Random;

import org.openrdf.model.Literal;
import org.openrdf.model.Statement;
import org.openrdf.model.URI;
import org.openrdf.model.ValueFactory;
import org.singularity.io.CloseablePipe;

/**
 * @author vjache
 *
 */
public class BigDataGenerator implements Runnable {

	private int _predNum;
	private int _subjNum;
	private int _propsPerSubj;
	private int _objNum;
	private ValueFactory _valFactory;
	private CloseablePipe<Statement> _dest;

	/**
	 * 
	 */
	public BigDataGenerator(
			CloseablePipe<Statement> aDestination,
			ValueFactory aValueFactory,
			int aPredNumber,
			int aSubjNumber,
			int aPropsPerSubject,
			int aObjectNum
			) 
	{
		_dest = aDestination;
		_predNum = aPredNumber;
		_subjNum = aSubjNumber;
		_propsPerSubj = aPropsPerSubject;
		_objNum = aObjectNum;
		_valFactory = aValueFactory;
	}

	/* (non-Javadoc)
	 * @see java.lang.Runnable#run()
	 */
	@Override
	public void run() {
		final Random rnd = new Random();
		
		String NS = "http://test.org/namespace/";
		final URI ctx = _valFactory.createURI(NS+"context-0");
		
		for(int i=0; i<_subjNum;i++)
		{
			final URI s = _valFactory.createURI(NS+"ID-"+i);
			for(int j=0; j<_propsPerSubj;j++)
			{
				final URI p = _valFactory.createURI(NS+"pred-"+rnd.nextInt(_predNum));
				final Literal lit = _valFactory.createLiteral("lit-"+rnd.nextInt(_objNum));
				try {
					_dest.push(_valFactory.createStatement(s, p, lit,ctx));
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
		}
	}

}
